package com.xhwl.logistics.converter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.pojo.cent.vehicle.VehcCarRecord;
import com.xhwl.common.pojo.cent.vehicle.VehcPayRecord;
import com.xhwl.logistics.vo.VehicleAccessRecordVO;
import com.xhwl.logistics.vo.VehiclePayRecordVO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

//@Component
public class ToPage {

    @Autowired
    private ToVehicleAccessRecordVO toVehicleAccessRecordVO;

    @Autowired
    private ToVehiclePayRecordVO toVehiclePayRecordVO;

    @Autowired
    private ToVehiclePayRecordBO toVehiclePayRecordBO;

    public Page<VehicleAccessRecordVO> toPageVehicleAccessRecordVO(Page<VehcCarRecord> source) {
        Page<VehicleAccessRecordVO> page = new Page<>();
        page.setRecords(toVehicleAccessRecordVO.toVehicleAccessRecordVOList(source.getRecords()));
        page.setCurrent(source.getCurrent());
        page.setPages(source.getPages());
        page.setSize(source.getSize());
        page.setTotal(source.getTotal());
        page.setOrders(source.getOrders());
        page.setSearchCount(source.isSearchCount());

        return page;
    }

    public Page<VehiclePayRecordVO> toPageVehiclePayRecordVO(Page<VehcPayRecord> source) {
        Page<VehiclePayRecordVO> page = new Page<>();

        //修改
//        page.setRecords(toVehiclePayRecordVO.toVehiclePayRecordVOList(source.getRecords()));

        page.setCurrent(source.getCurrent());
        page.setPages(source.getPages());
        page.setSize(source.getSize());
        page.setTotal(source.getTotal());
        page.setOrders(source.getOrders());
        page.setSearchCount(source.isSearchCount());

        return page;
    }

    public <P extends IPage<?>, T> Page<T> toPage(P p, List<T> list) {
        Page<T> page = new Page<>();
        page.setCurrent(p.getCurrent());
        page.setPages(p.getPages());
        page.setSize(p.getSize());
        page.setTotal(p.getTotal());
        page.setRecords(list);

        return page;
    }

}
